﻿#include "EquationSolver.h"

using namespace std;
double L = 10, r = 1, V = 12.4;
class Func : public Function
{
public:
    double operator()(double x) {
        return V - L * (0.5 * M_PI * r * r - r * r * asin(x / r) - x * sqrt(r * r - x * x));
    }
    double diff(double x) {
        return -L * (-r / sqrt(1 - pow(x / r, 2)) - sqrt(r * r - x * x) + x * x / sqrt(r * r - x * x));
    }
};

int main() {
    cout << "------------TestE:--------------------" << endl;
    Func func;
    BisectionSolver b(0, r, 0.01, 100, func);
    NewtonSolver n(0.5 * r, 0.01, 100, func);
    SecantSolver s(0, r, 0.01, 100, func); 
    cout << "BisectionSolver :" << "  root = " << b.solve() << "    f(root) = " << func(b.solve()) << endl;
    cout << "NewtonSolver :" << "    " << "root = " << n.solve() << "    f(root) = " << func(n.solve()) << endl;
    cout << "SecantSolver :" << "    " << "root = " << s.solve() << "    f(root) = " << func(s.solve()) << endl;
    return 0;
}